//
//  PageModel.swift
//  Employee
//
//  Created by swordjoy on 2017/4/5.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation
import SwiftyJSON

struct PageModel {
  
  var page: String = "1"
  var size: String = "20"
  var totalAmount: String?
  var totalPages: String?
  var headerPage: String = "1"
  var nextPage: String {
    
    return "\(page.sj.intValue + 1)"
    
  }
  
  
  init() {
    self.page = "1"
    self.size = "20"
  }
  
  init(json: JSON) {
  
    self.page = json["page"].stringValue
    self.size = json["size"].stringValue
    self.totalAmount = json["totalAmount"].stringValue
    self.totalPages = json["totalPages"].stringValue
    
  }
  
  /// 更新页数
  mutating func updatePage(json: JSON) {
  
    self.page = json["page"].stringValue
    self.size = json["size"].stringValue
    self.totalAmount = json["totalAmount"].stringValue
    self.totalPages = json["totalPages"].stringValue
    
  }
  
  
  /// 是否有下一页
  var hasNextPage: Bool {
    
    if "0" == totalPages { return false }
    
    return page != totalPages
  }
  
  
  /// 是否有数据
  var hasData: Bool {
    return totalAmount != "0"
  }
  
  
}
